/*
 * 文件名: PerWeekOrPerMonthDialog.java
 * 版    权：  Copyright PingAn Technology All Rights Reserved.
 * 描    述: [该类的简要描述]
 * 创建人: EX-XUJIAO001
 * 创建时间: 2012-1-17
 * 
 * 修改人：
 * 修改时间:
 * 修改内容：[修改内容]
 */
package app.widget.calendar.dialog;

import android.content.Context;
import android.view.View;
import app.widget.BaseDialog;
import app.widget.calendar.dialog.SingleWheelLinearLayout.OnSingleWheelChangeListener;


/**
 * @author EX-XUJIAO001
 * @date 2012-1-17
 * @version [Android PABank C01, @2012-1-17]
 * @description
 */
public class PerWeekOrPerMonthDialog extends BaseDialog {
	/**
	 * 外部传进来的标志
	 */
	private int tag;

	/**
	 * 返回view
	 */
	private View contentView;
	/**
	 * 上下文
	 */
	private Context context;
	/**
	 * 返回的结果 int
	 */
	private int mResult;
	/**
	 * 设置最小年
	 */
	private int minTime;
	/**
	 * 设置最大年
	 */
	private int maxTime;

	/**
	 * 
	 * [构造简要说明]
	 * 
	 * @param context
	 *            上下文
	 * @param title
	 *            标题
	 */
	public PerWeekOrPerMonthDialog(Context context, String title) {
		super(context);
		setTitle(title);
	}

	/**
	 * 
	 * [构造简要说明]
	 * 
	 * @param context
	 *            上下文
	 * @param title
	 *            标题
	 * @param tag
	 *            标志
	 */
	public PerWeekOrPerMonthDialog(Context context, String title, int tag) {
		super(context);
		this.context = context;
		this.tag = tag;
		setTitle(title);
		initDate();
	}
	
	/**
	 * 
	 * [构造简要说明]
	 * 
	 * @param context
	 *            上下文
	 * @param title
	 *            标题
	 * @param tag
	 *            标志
	 */
	public PerWeekOrPerMonthDialog(Context context, String title, int tag ,int minTime ,int maxTime) {
		super(context);
		this.context = context;
		this.tag = tag;
		this.minTime = minTime;
		this.maxTime = maxTime;
		setTitle(title);
		initDate();
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] getter
	 * 
	 * @return int
	 */
	public int getTag() {
		return tag;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] setter
	 * 
	 * @param tag
	 *            标志
	 */
	public void setTag(int tag) {
		this.tag = tag;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 初始化数据
	 */
	private void initDate() {
		SingleWheelLinearLayout singleWheelLinearLayout = null;
		if (tag == 3) {
			singleWheelLinearLayout = new SingleWheelLinearLayout(
					context, tag ,minTime,maxTime);
		} else {
			singleWheelLinearLayout = new SingleWheelLinearLayout(
					context, tag);
		}
		

		contentView = singleWheelLinearLayout;
		singleWheelLinearLayout
				.setOnSingleWheelChangeListener(new OnSingleWheelChangeListener() {

					@Override
					public void onSingleWheelChange(int result) {
						
						mResult = result;
						
					}

					@Override
					public void onScrollState(boolean isScroll) {
						if (isScroll) {
							setBtn1Enable(false);
							setBtn2Enable(false);
						} else {
							setBtn1Enable(true);
							setBtn2Enable(true);
						}
						
					}
				});

		setBtn1ClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (onScrollEndListener != null) {
					onScrollEndListener.onScrollEndListener(mResult);
				}

				PerWeekOrPerMonthDialog.this.dismiss();
			}
		});

		setBtn2ClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				PerWeekOrPerMonthDialog.this.dismiss();
			}
		});
	}

	@Override
	public View createContentView() {

		return contentView;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述]
	 * 
	 * @author EX-XUJIAO001
	 * @version [Android PABank C01, 2012-1-17]
	 */
	public interface OnScrollEndListener {
		/**
		 * 
		 * [一句话功能简述]<BR>
		 * [功能详细描述]
		 * 
		 * @param result
		 *            结果
		 */
		void onScrollEndListener(int result);
	}

	/**
	 * 回调
	 */
	private OnScrollEndListener onScrollEndListener;

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] getter
	 * 
	 * @return OnScrollEndListener
	 */
	public OnScrollEndListener getOnScrollEndListener() {
		return onScrollEndListener;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述]
	 * 
	 * @param onScrollEndListener
	 *            回调监听
	 */
	public void setOnScrollEndListener(OnScrollEndListener onScrollEndListener) {
		this.onScrollEndListener = onScrollEndListener;
	}

}
